import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreImageService extends BaseService<any> {
  private readonly logger = new Logger(CoreImageService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * thumb
   * 对应 PHP: CoreImageService_core::thumb()
   * 逻辑类型: undefined - undefined
   */
  async thumb(site_id: number, file_path: number, thumb_type: number, is_throw_exception: number) {
    // 基于PHP真实逻辑: thumb
    // PHP原文: //文件转url         $file_path = path_to_url($file_path);         $file_parse = parse_url($file_path);         $scheme = $file_parse['scheme'] ?? '';    ...
//文件转url
        const file_path = path_to_url(file_path];
        const file_parse = parse_url(file_path];
        const scheme = file_parse.scheme || '';
        const host = file_parse.host || '';
        const file_domain = scheme  + '://' . host;
        //判断是哪个云上传的实例
        const storage_type_list = this.coreStorageService.getStorageConfigList();
        foreach(storage_type_list as k => v){
            const item_params = v.params || [];
            const item_domain = item_params.domain || '';
            const item_storage_type = v.storage_type;
            if(str_contains(file_path, '_'.item_storage_type)){
                this.upload_driver = this.driver(site_id, item_storage_type);
            }} } else {
                if (item_domain == file_domain) {
                    this.upload_driver = this.driver(site_id, item_storage_type);
                }
            }
  }
}
